#include<bits/stdc++.h>
#define mk make_pair
#define int long long 
#define mid ((l+r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1) 
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=5e5+5;
inline pair<int,int> Max(pair<int,int>A,pair<int,int>B){
	if(A.first*B.second<B.first*A.second)return B;
	else return A;
}
struct node{
	vector<pair<int,int> >L,R;
	inline void Insert(pair<int,int>x){
		while(L.size()&&L.back().first>x.first)L.pop_back();
		while(R.size()&&R.back().first<x.first)R.pop_back();
		L.push_back(x),R.push_back(x);
		return;
	}
}s;
int n,m;
int a[N];
pair<int,int>ans[N],tree[N];
vector<pair<int,int>>Q[N];
inline int lowbit(int x){return x&(-x);}
void modify(int x,pair<int,int>V){
	while(x){
		tree[x]=Max(tree[x],V);
		x-=lowbit(x);
	}
}
pair<int,int> ask(int x){
	pair<int,int>cnt=mk(0,1);
	while(x<=n+1){
		cnt=Max(cnt,tree[x]);
		x+=lowbit(x);
	}
	return cnt;
}
void sol(){
	for(int i=1;i<=n+1;i++)tree[i]=mk(0,1);
	for(int i=0;i<=n+1;i++){
		for(auto x:s.L)modify(x.second+1,mk((a[i]-x.first)*(a[i]-x.first),i-x.second));
		for(auto x:s.R)modify(x.second+1,mk((a[i]-x.first)*(a[i]-x.first),i-x.second));
		s.Insert(mk(a[i],i));
		for(auto asd:Q[i])ans[asd.second]=ask(asd.first);
	}
}
signed main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)read(a[i]),a[i]+=a[i-1];
	read(m);
	for(int i=1;i<=m;i++){
		int l,r;
		read(l,r);
		Q[r].push_back(mk(l,i));
	}
	sol();
	for(int i=1;i<=m;i++){
		int x=__gcd(ans[i].first,ans[i].second);
		ans[i].first/=x,ans[i].second/=x;
		write(ans[i].first),putch(' '),write(ans[i].second),putch('\n');
	}
	flush();
	return 0;
}
